package com.yanqu.road.server.cmd.activity.douluoshrek;

import com.yanqu.road.pb.activity.DouLuoShrekProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shrek.DouLuoShrekModule;
import com.yanqu.road.server.manger.activity.shrek.DouLuoShrekMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_DOULUOSHREK_BUILDING_LEVEL_UP_PRE, desc = "史瑞克建筑坑位升级判断")
public class ShrekBuildingLevelUpPreCmd extends AbstractCommand {

    private int activityId;
    private int buildingId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoShrekProto.LevelUpBuildingPreReqMsg reqMsg = DouLuoShrekProto.LevelUpBuildingPreReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        buildingId = reqMsg.getBuildingId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(DouLuoShrekMgr.getActivityTimeAcId() != activityId){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!DouLuoShrekMgr.activityInTime()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        ret = player.getModule(DouLuoShrekModule.class).levelUpPre(buildingId);
    }

    @Override
    public void sendData(GamePlayer player) {
        DouLuoShrekProto.LevelUpBuildingPreRespMsg.Builder respMsg = DouLuoShrekProto.LevelUpBuildingPreRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_DOULUOSHREK_BUILDING_LEVEL_UP_PRE, respMsg);
    }
}
